\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{compat=1.17}

\usepgfplotslibrary{patchplots}


\begin{document}


\pgfplotsset{samples=5}

\long\def\compileTwice#1{%
	%
	\begingroup
	\pgfplotsset{
		small,
		every axis post/.style={
			title/.add={}{ (Line number \the\inputlineno)}
		},
	}%
	\noindent
	\def\VARIANT{lua}%
	#1%
	\def\VARIANT{gnuplot}%
	#1%
	\def\VARIANT{filled}%
	#1%
	\endgroup

}

\compileTwice{%
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
	\begin{axis}[
		title=\VARIANT,
		view={0}{90},
	]
	\addplot3[
		samples=5,
		contour \VARIANT={
			number=3,
		}
	] 
		{x*y};

	\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
		]
	\addplot3[
		samples=5,
		contour \VARIANT={
			levels={-20,0.5,10} % FAILS
		}
	] 
		{x*y};

		\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
			xmin=0,xmax=1,
			ymin=0,ymax=1,
		]

	\addplot3[contour \VARIANT={levels={0,0.5,0.6,1}}] 
		coordinates {
		(0,0,0) (1,0,0)

		(0,1,0) (1,1,1)
	};
		\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
		]

	\addplot3[contour \VARIANT={number=4}] 
		{x^2};

		\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
		]

\addplot3[
    contour \VARIANT={},
    samples=10,
    domain=0:1,
] {x*(1-x)*y*(1-y)};

		\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
		]

\addplot3 [
    contour \VARIANT={},
    samples=5, % 25
    domain=0:2,
    y domain=0:1,
] {exp(-x) * sin(pi*deg(y))};

		\end{axis}
	\end{tikzpicture}%
}


\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
		]

\addplot3 [
    contour \VARIANT
] {x*y};

		\end{axis}
	\end{tikzpicture}%
}

\vspace{1cm}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
		]

\addplot3 [
    contour \VARIANT
] {exp(0-x^2-y^2)};


		\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	%\tracingcommands=2\tracingmacros=2
		\begin{axis}[
			title=\VARIANT,
			view={0}{90},
			xmin=0,xmax=1,
			ymin=0,ymax=1,
		]

\addplot3 [
    contour \VARIANT
] coordinates {
    (0,0,0) (1,0,0)   (2,0,0)   (3,0,0)

    (0,1,0) (1,1,0.6) (2,1,0.7) (3,1,0.5)

    (0,2,0) (1,2,0.7) (2,2,0.8) (3,2,0.5)
};


		\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	\begin{axis}[
			title=\VARIANT,
	]
		\addplot3 [surf,shader=interp] coordinates {
			(0,0,0) (1,0,0)   (2,0,0)   (3,0,0)

			(0,1,0) (1,1,0.6) (2,1,0.7) (3,1,0.5)

			(0,2,0) (1,2,0.7) (2,2,0.8) (3,2,0.5)
		};
		\addplot3 [
			contour \VARIANT={
				/pgfplots/contour external/output point meta=rawz,
			},
			z filter/.code={\def\pgfmathresult{1}},
		] coordinates {
			(0,0,0) (1,0,0)   (2,0,0)   (3,0,0)

			(0,1,0) (1,1,0.6) (2,1,0.7) (3,1,0.5)

			(0,2,0) (1,2,0.7) (2,2,0.8) (3,2,0.5)
		};
	\end{axis}
	\end{tikzpicture}%
}

\compileTwice{
	\begin{tikzpicture}
	\begin{axis}[
			title=\VARIANT,
		domain=-2:2,enlarge x limits,
		view={0}{90},
	]
		\addplot3 [
			contour gnuplot={number=14},
			thick,
		] {exp(-x^2-y^2)*x};
	\end{axis}
	\end{tikzpicture}%
}


\compileTwice{%
	\begin{tikzpicture}
	\begin{axis}[
			title=\VARIANT,
		domain=-2:2,
	]
		\addplot3 [
			contour \VARIANT={
				contour dir=x,
				labels=false,
				number=15,
			},
			thick,
		] {exp(-x^2-y^2)*x};
	\end{axis}
	\end{tikzpicture}%
}


\compileTwice{%
	\begin{tikzpicture}
	\begin{axis}[view={60}{30},axis equal image,
		title=\VARIANT,
	]
		\addplot3 [
			contour \VARIANT={
				contour dir=x,
				number=20,
				labels=false,
			},
			samples=5, %30
			domain=-1:1,y domain=0:2*pi,
		] (
			{sqrt(1-x^2) * cos(deg(y))},
			{sqrt( 1-x^2 ) * sin(deg(y))},
			 x
		);
	\end{axis}
	\end{tikzpicture}%
}

\compileTwice{%
	\begin{tikzpicture}
	\begin{axis}[
		title=\VARIANT,
		xlabel=$x$,ylabel=$y$,
		enlargelimits=false,
		3d box=complete,
	]
		\addplot3 [surf] {x^2-y^2};
		\addplot3 [
			contour \VARIANT={contour dir=y,
				draw color=red,labels=false},
			y filter/.expression={-5},
		] {x^2-y^2};
		\addplot3 [
			contour \VARIANT={contour dir=x,
				draw color=blue,labels=false},
			x filter/.expression={5},
		] {x^2-y^2};
		\addplot3 [
			contour \VARIANT={contour dir=z,
				draw color=black,labels=false},
			z filter/.expression={25},
		] {x^2-y^2};
	\end{axis}
	\end{tikzpicture}%
}

\compileTwice{%
	\begin{tikzpicture}
		\begin{axis}[view={0}{90},
			title=\VARIANT,
		]
			\addplot3 [domain=0:2*pi,trig format plots=rad,
				contour \VARIANT={
					levels={-0.4,-0.25,0,0.3,0.9}
				},
			] {sin(x)*sin(y)};
		\end{axis}
	\end{tikzpicture}%
}


\compileTwice{%
\begin{tikzpicture}
  \pagecolor{white}
  \begin{axis}
  [
    title={\VARIANT},
    xlabel={$x$},
    ylabel={$y$},
    zlabel={$z$},
    view/h=70,
    view/v=50,
  ]
    \addplot3
    [
      surf,
      shader=interp,
      patch type=bilinear,
      mesh/ordering=y varies,
      point meta=
      {
        \thisrow{v}
      },
    ]
    table {unittest_contourlua.data_small.txt};
    \addplot3
    [
      contour \VARIANT=
      {
        levels={0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
		/pgfplots/contour external/output point meta=explicit,
      },
      mesh/ordering=y varies,
      point meta=
      {
        \thisrow{v}
      },
    ]
    table {unittest_contourlua.data_small.txt};
  \end{axis}
\end{tikzpicture}%
}

\compileTwice{%
\begin{tikzpicture}
  \pagecolor{white}
  \begin{axis}
  [
    title={\VARIANT},
    xlabel={$x$},
    ylabel={$y$},
    zlabel={$z$},
    clip mode=individual,
    colorbar horizontal,
    view/h=0,
    view/v=90,
  ]
  \iffalse
    \addplot3
    [
      surf,
      shader=interp,
      patch type=bilinear,
      domain=-3:3,
      domain y=-2:2,
      samples=30,
      samples y=20,
    ]
    {64*x*y*exp(-x^2-y^2)};
	\fi

    \addplot3
    [
      domain=-3:3,
      domain y=-2:2,
      samples=7, % 30
      samples y=5, %20
      contour \VARIANT=
      {
        draw color=mapped color!80!white,
        labels over line,
        levels={-10,-5,0,5,10},
      },
      thick,
    ]
    {64*x*y*exp(-x^2-y^2)};
  \end{axis}
\end{tikzpicture}%
}
\end{document}

